package com.lib.common.helper.sharehelper.share

import android.content.Context
import com.tencent.mm.opensdk.modelbase.BaseReq
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import com.lib.common.helper.sharehelper.AShareListener
import com.lib.common.helper.sharehelper.entity.ShareData
import com.lib.common.helper.sharehelper.entity.ShareType
import com.lib.framework.base.BaseActivity
import com.lib.framework.manager.thread.mainThreadRun
import com.xiangwushuo.thirdparty.weixin.WeiXinHelper

/**
 * 微信朋友圈分享
 *
 * @author keanbin
 */
class WeiXinFriendCircleShare(context: Context) : WeiXinFriendShare(context) {

    override fun getShareType() = ShareType.WEI_XIN_FRIEND_CIRCLE_SHARE

    override fun share(activity: BaseActivity, shareData: ShareData, l: AShareListener): Boolean {
        if (!WeiXinHelper.isInstallWeiXin()) {
            mainThreadRun {
                l.onShareFail("请先安装微信")
            }
            return false
        }

        if (!WeiXinHelper.isSupportedFriendCircle()) {
            mainThreadRun {
                l.onShareFail("您安装的微信版本不支持朋友圈分享")
            }
            return false
        }

        return super.share(activity, shareData, l)
    }

    override fun shareDataToBaseReq(shareData: ShareData): BaseReq? {
        var req = super.shareDataToBaseReq(shareData)
        req?.let {
            var req = it as SendMessageToWX.Req
            req.scene = SendMessageToWX.Req.WXSceneTimeline
        }

        return req
    }

}